package top.yamhk.agent.entity.enums;

import java.util.stream.Stream;

/**
 * 消息类型枚举
 *
 * @author 庆 HongKong
 * @date 2019/5/18 22:11
 */
public enum MsgType {
    /**
     * 广播
     */
    SINGLE2ALL(-1, "广播"),
    /**
     * 自言自语
     */
    SINGLE2SELF(0, "自言"),
    /**
     * 祈祷
     */
    PRAY(1, "祈祷"),
    /**
     * 倾听
     */
    SINGLE2CLIENT(2, "倾听"),
    /**
     * 私聊
     */
    SINGLE2SINGLE(3, "私聊"),
    /**
     * 群聊
     */
    SINGLE2GROUP(4, "群聊"),
    /**
     * 群聊
     */
    MSG_BOARD(5, "留言"),
    /**
     * 心跳
     */
    HEART_BEAT_01(6, "FWQ心跳"),
    /**
     * 心跳
     */
    HEART_BEAT_02(7, "KHD心跳"),
    /**
     * 握手包
     */
    SYN_SENT(11, "第一次握手"),
    /**
     * 握手包
     */
    SYN_RECV(12, "第二次握手"),
    /**
     * 握手包
     */
    ESTABLISHED(13, "第三次握手"),
    /**
     * HTTP连接建立==========================================
     */
    ONLINE(20, "ONLINE"),
    /**
     * 指令包
     */
    ORDER(50000, "指令包"),
    ASK(50001, "询问"),
    ANS(50002, "回答"),
    MONITOR(50003, "监控"),
    /**
     * 反馈
     */
    FEEDBACK(50004, "反馈"),
    /**
     * 发布
     */
    PUBLISH(50005, "发布"),
    /**
     * 订阅
     */
    SUBSCRIBE(50006, "订阅");

    /**
     * 下标
     */
    private final Integer code;
    /**
     * 描述
     */
    private final String desc;

    MsgType(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static MsgType of(int i) {
        return Stream.of(values()).filter(e -> e.code.equals(i)).findFirst()
                .orElseThrow(() -> new IllegalArgumentException("illegal value" + i));
    }


    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }
}
